package cn.com.adcc.utils;

import cn.com.adcc.bean.MessageBean;
import org.apache.log4j.Logger;

import com.sun.management.OperatingSystemMXBean;

import javax.management.MBeanServerConnection;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URL;




/**
 * Created by anzilu on 2015/10/12.
 */
public class Utils {

    private static Logger logger = Logger.getLogger(Utils.class);
    //public static BlockingQueue<String> blockingQueue=new LinkedBlockingQueue<String>();
    private static String netStatus="";

    public static void startJettyServer(){

        new Thread(new JettyServer()).start();
    }

    public static MessageBean messageBean=new MessageBean();

    public static void main(String[] args){

        System.out.println("Version 1.0.18");
//        startJettyServer();
//        while(true){
//
//            if(isNetConnected()){
//
//                System.out.println("网络通了");
//            }
//
//            try {
//                Thread.sleep(5000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
    }

    public static boolean isNetConnected(){
        URL url = null;
        try {
            url = new URL("http://www.aliyun.com/");
            //url = new URL(Config.END_POINT);
            try {
                InputStream in = url.openStream();
                in.close();
                netStatus="网络连接正常";
                return true;
            }
            catch (IOException e) {

                if(!netStatus.equals("网络连接失败")){
                    netStatus="网络连接失败";
                    logger.error("网络连接失败！"+e.toString());
                }
                return false;
            }
        }
        catch (MalformedURLException e) {
            if(netStatus.equals("网络连接失败")){
                netStatus="网络连接失败";
                logger.error("网络连接失败！"+e.toString());
            }
            return false;
        }
    }


}
